package com.punch.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punch.common.dto.order.OrderDetailDTO;
import com.punch.order.mapper.CommonOrderDetailMapper;
import com.punch.order.model.CommonOrderDetail;
import com.punch.order.service.CommonOrderDetailService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 订单详情 服务实现类
 * </p>
 *
 * @author wjj
 * @since 2020-12-09
 */
@Service
public class CommonOrderDetailServiceImpl extends ServiceImpl<CommonOrderDetailMapper, CommonOrderDetail> implements CommonOrderDetailService {

    /**
     * 保存订单详情
     *
     * @param productList 产品列表
     * @param userId      用户uid
     * @param orderSN     订单流水号
     * @param orderId     订单id
     */
    @Override
    public void saveDetail(List<OrderDetailDTO> productList, Long userId, String orderSN, Long orderId) {
        List<CommonOrderDetail> insertList = new ArrayList<>(2);
        productList.forEach(p -> {
            CommonOrderDetail commonOrderDetail = new CommonOrderDetail();
            BeanUtil.copyProperties(p, commonOrderDetail);
            commonOrderDetail.setOrderId(orderId);
            commonOrderDetail.setOrderSN(orderSN);
            commonOrderDetail.setCreateId(userId);
            insertList.add(commonOrderDetail);
        });
        saveBatch(insertList);
    }
}
